const { defineConfig } = require('@vue/cli-service')

const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')

const CompressionPlugin = require('compression-webpack-plugin')

module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      new CompressionPlugin({
        algorithm: 'gzip', // 使用gzip压缩
        test: /\.js(\?.*)?$|\.html$|\.css$/i, // 匹配文件名
        filename: '[path][base].gz', // 压缩后文件名
        threshold: 8192, // 对超过8k的数据压缩
        minRatio: 0.8, // 压缩率小于0.8才会压缩
        deleteOriginalAssets: false // 是否删除未压缩的源文件
      })
    ]
  }
})
